#ifndef _XPRLOADGEN_H_
#define _XPRLOADGEN_H_

#include <assert.h>
#include <unistd.h>
#include <string>

#include "SingleCall.h"

#ifdef USE_LOADGEN_GUI
    #include "ui_main.h"
    #include <QObject>
    #include <QThread>
    #include <QString>
    #include <QVector>
    class QApplication;
#else
    #include <boost/shared_ptr.hpp>
    #include <boost/thread/thread.hpp>
#endif // USE_LOADGEN_GUI


using std::string;
using std::vector;

void usage(const char* szExecutable);



class Oxsipgen
    #ifdef USE_LOADGEN_GUI
        : public QThread
    #else
        : public boost::noncopyable
    #endif // USE_LOADGEN_GUI
{
    #ifdef USE_LOADGEN_GUI

        Q_OBJECT
    signals:
        void addNewThreadToTable( int loop, QString scenefile );

    public slots:
        void forceHangup();
        void changeAudioThread(const int);
        void runSlot();
        void loadNewSceneSlot( const QString );
        void quitkill();
        void quitfriendly();
        void updateStatistics();

    public:
        void setQApplication(QApplication*);
    #endif // USE_LOADGEN_GUI


    public :
        Oxsipgen();
        ~Oxsipgen();
        void run();             // aka startThreads
        void loadNewScene(const string);
        void operator()();

        static Oxsipgen *getInstance();
        EventHistory* getHistoryOfThread(int threadId);
        vector<LOADGEN_SINGLECALL_STRUCT> getListOfThreadsInfo();
        bool saveThreadsHistory(string, int);
        void terminateAllCalls();
        uint getNumberOfThreads();
        void waitForThreadsToTerminate();
        void quit(bool=false);

    private:
        bool sceneLoaded;

        #ifdef USE_LOADGEN_GUI
        QVector<SingleCall*> scArray;
        #else
        boost::shared_ptr<SingleCall> *scArray;
        #endif // USE_LOADGEN_GUI

        static Oxsipgen * _theInstance;
        #ifdef USE_LOADGEN_GUI
        QMainWindow window;
        Ui::MainWindow ui;
        QApplication *p_app;
        #else
        boost::thread_group thrds;
        #endif // USE_LOADGEN_GUI

        void setAudioThread(const int);
        void sceneCleanup();

};

#endif //_XPRLOADGEN_H_

